package houserent_view;

import houserent_domain.House;
import houserent_service.HouseService;
import utils.Utility;

/**
 * 1.显示界面
 * 2.接收用户的输入
 * 3.调用HouseService完成对房屋信息的各种操作
 */
public class HouseView {
    private boolean loop = true;//控制显示菜单
    private char key = ' ';//接收用户选择
    private HouseService houseService = new HouseService(10);



//编写listHouse()显示房屋列表
    public void listHouses(){
        System.out.println("==========房屋列表==========");
        System.out.println("编号\t\t房主\t\t电话\t\t地址\t\t月租\t\t状态(已出租/未出租)");
        House[] houses = houseService.list();//得到所有房屋信息
        for(int i = 0; i < houses.length; i++){
            if(houses[i] == null){//如果为null，就不用再显示了
                break;
            }
            System.out.println(houses[i]);
        }
        System.out.println("===========房屋列表显示完毕=========");
    }
    //显示菜单
    public void mainMenu() {
        do {
            System.out.println("----------房屋出租系统---------");
            System.out.println("\t\t\t1. 新增房源");
            System.out.println("\t\t\t2. 查找房屋");
            System.out.println("\t\t\t3. 删除房屋信息");
            System.out.println("\t\t\t4. 修改访问信息");
            System.out.println("\t\t\t5. 显示房屋信息");//房屋列表
            System.out.println("\t\t\t6. 退出");

            System.out.println("请输入你的选择（1-6）：");
            key = Utility.readChar();
            switch(key) {
                case '1' :
                    System.out.println("新增");
                    break;
                case '2' :
                    System.out.println("查找");
                    break;
                case '3' :
                    System.out.println("删除");
                    break;
                case '4' :
                    System.out.println("修改");
                    break;
                case '5' :
                    System.out.println("房屋列表");
                    listHouses();
                    break;
                case '6' :
                    System.out.println("退出");
                    loop = false;
                    break;
            }
        } while (loop);
    }
}
